package org.ms.mtx.example;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * The Method Monitor
 *
 * @author lry
 */
public class MethodMonitor implements MethodInterceptor {

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("1=========");
        Object object = proxy.invokeSuper(obj, args);
        System.out.println("2=========");
        return object;
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(new MethodMonitor());
        enhancer.setSuperclass(Demo.class);
        Demo demo = (Demo) enhancer.create();
        demo.test("echo");
    }

}
